package com.huarui.employee.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.ewaf.framework.dao.impl.BaseDaoImpl;
import com.huarui.employee.dao.IEmployeeDao;
import com.huarui.employee.model.Employee;

public class EmployeeDaoImpl extends BaseDaoImpl implements IEmployeeDao  {

	@SuppressWarnings("unchecked")
	@Override
	public List<Employee> getByName(String name) {
	return	(List<Employee>)getSqlMapClientTemplate().queryForList(namespace+".updateIncumbent", name);
	}

	@SuppressWarnings("unchecked")
	@Override
	public boolean updateStaffRoles(Integer id, int roles) {
		Map map = new HashMap();
		map.put("id", id);
		map.put("roles", roles);
		
		return getSqlMapClientTemplate().update(namespace +".updateStaffRoles", map) == 1;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Employee> getAllStaffs() {
		
		List list=getSqlMapClientTemplate().queryForList(namespace + ".queryForStaffList");
		
		return list;
	}

	@SuppressWarnings("unchecked")
	@Override
	public boolean updateStatus(Integer id, boolean incumbent) {
		Map map = new HashMap();
		map.put("id", id);
		map.put("incumbent", incumbent);
	return	getSqlMapClientTemplate().update(namespace+".updateIncumbent",map)==1;

	}
	
/*
	@SuppressWarnings("unchecked")
	@Override
	public void createStaff(Employee employee) {
		Map map = new HashMap();
		map.put("userId", userId);
		map.put("companyId", companyId);
		getSqlMapClientTemplate().update(namespace + "createStaff", map);
		
	}
*/

	@Override
	public Employee getByCode(String code) {
	return	(Employee)getSqlMapClientTemplate().queryForObject(namespace+".getByCode",code);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Employee> getByPyCode(String pyCode) {
		
		return	getSqlMapClientTemplate().queryForList(namespace+".getByPyCode",pyCode);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Employee getEmployeeByUserId(Integer userId,Integer companyId,Integer isDelete) {
		
		Map map = new HashMap();
		map.put("userId", userId);
		map.put("companyId",companyId);
		map.put("isDelete", isDelete);
		return (Employee)getSqlMapClientTemplate().queryForObject(namespace+".getEmployeeByUserId",map);
	}

	@SuppressWarnings("unchecked")
	public List<Employee> getEmployeeByCompanyId(Map map){
		
		List<Employee> list=getSqlMapClientTemplate().queryForList(namespace+".getEmployeeByCompanyId",map); 
		return list;
	}

	@SuppressWarnings("unchecked")
	@Override
	public Employee getJoinDictionary(Integer id, String varGroup) {
		Map map = new HashMap();
		map.put("id", id);
		map.put("varGroup", varGroup);
		return  (Employee)getSqlMapClientTemplate().queryForObject(namespace+".getjoindictionary",map);
	}

	@SuppressWarnings("unchecked")
	@Override
	public int countByConditions(Map map) {
		
		return (Integer)getSqlMapClientTemplate().queryForObject(namespace+".countByConditions",map);
	}

	@Override
	public String getNameByIdAndCompanyId(Integer id, Integer companyId) {
		Map<String, Integer> map = new HashMap<String, Integer>();
		map.put("id", id);
		map.put("companyId", companyId);
		return (String) getSqlMapClientTemplate().queryForObject(namespace+".getNameByIdAndCompanyId", map);
		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Map> getListBycondition(Map map) {
		return this.getSqlMapClientTemplate().queryForList(namespace+".getListBycondition",map);
	}
	
	@Override
	public Integer getCountByCondition(Map map){
		return  (Integer) this.getSqlMapClientTemplate().queryForObject(namespace+".getCountByCondition", map);
	}
	@Override
	public  Employee getEmployeeByCodeAndCompanyId(Map map){
		
		return  (Employee)getSqlMapClientTemplate().queryForObject(namespace+".getEmployeeByCodeAndCompanyId",map);
	}

	@Override
	public Employee getEmployeeForUpdate(Integer id) {
		
		return (Employee)getSqlMapClientTemplate().queryForObject(namespace + ".getEmployeeForUpdate", id);
	}
}
